package com.ruoyi.system.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.ReviewContent1;
import com.ruoyi.system.service.IReviewContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.VideoReviewMapper;
import com.ruoyi.system.domain.VideoReview;
import com.ruoyi.system.service.IVideoReviewService;

/**
 * 视频评论Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-05-21
 */
@Service
public class VideoReviewServiceImpl implements IVideoReviewService
{
    @Autowired
    private VideoReviewMapper videoReviewMapper;
    @Autowired
    private IReviewContentService reviewContentService;

    /**
     * 查询视频评论
     * 
     * @param id 视频评论主键
     * @return 视频评论
     */
    @Override
    public VideoReview selectVideoReviewById(Long id)
    {
        VideoReview videoReview = videoReviewMapper.selectVideoReviewById(id);
        ReviewContent1 byId = reviewContentService.getById(id.toString());
        videoReview.setContent(byId.getContent());
        return videoReview;
    }


    @Override
    public List<VideoReview> selectVideoReviewList()
    {
//        Long id = videoReview.getId();
//        String content = videoReview.getContent();
//        ReviewContent reviewContent = new ReviewContent();
//        reviewContent.setId(id.toString());
//        reviewContent.setContent(content);
//        reviewContentService.insert(reviewContent);
        List<VideoReview> videoReviews = videoReviewMapper.selectVideoReviewList();
        System.err.println(videoReviews);
        for (VideoReview videoReview : videoReviews) {
            String id = String.valueOf(videoReview.getId());
            System.err.println(id);
            String videoId="video"+id;
            ReviewContent1 reviewContent = reviewContentService.getById(videoId);
            String content = reviewContent.getContent();
            System.err.println(content);
            videoReview.setContent(content);
        }
        System.err.println(videoReviews);
        return videoReviews;
    }

    /**
     * 新增视频评论
     *
     * @param videoReview 视频评论
     * @return 结果
     */
    @Override
    public int insertVideoReview(VideoReview videoReview)
    {
        videoReview.setCreateTime(DateUtils.getNowDate());
        int i = videoReviewMapper.insertVideoReview(videoReview);
        if (i>0){
            Long id = videoReview.getId();
            String content = videoReview.getContent();
            ReviewContent1 reviewContent = new ReviewContent1();
            reviewContent.setId("video"+id.toString());
            reviewContent.setContent(content);
            reviewContentService.insert(reviewContent);
        }
        return i;
    }


    /**
     * 批量删除视频评论
     * 
     * @param ids 需要删除的视频评论主键
     * @return 结果
     */
    @Override
    public int deleteVideoReviewByIds(Long[] ids)
    {
        return videoReviewMapper.deleteVideoReviewByIds(ids);
    }

    /**
     * 删除视频评论信息
     * 
     * @param id 视频评论主键
     * @return 结果
     */
    @Override
    public int deleteVideoReviewById(Long id)
    {
        return videoReviewMapper.deleteVideoReviewById(id);
    }
}
